package net.dasviertel.buddylockscreen.activities;

import java.util.ArrayList;

import net.dasviertel.buddylockscreen.application.AppPreferences;
import net.dasviertel.buddylockscreen.data.ContactsDataManager;
import net.dasviertel.buddylockscreen.data.ContactsObject;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.monitorcontactschanges.R;

public class ChoosePhoneActivity extends Activity implements OnItemClickListener {

	private TextView selectedContactTextView;
	private ListView chooseNumberListView;
	private ArrayAdapter<String> chooseNumberListViewAdapter;
	private ArrayList<String> numbersList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_choose_number);

		selectedContactTextView = (TextView) findViewById(R.id.tv_selected_contact_choose_phone_activity);
		
		chooseNumberListView = (ListView) findViewById(R.id.lv_choose_number);

		ContactsDataManager.getInstance().init();

		ContactsObject currentContact = ContactsDataManager.getInstance().getContactByName(AppPreferences.getInstance().getContactName());
		
		Log.d("", ">> currentContact.getName()" + currentContact.getName());
		
		selectedContactTextView.setText(getResources().getString(R.string.phone_numbers_of) + AppPreferences.getInstance().getContactName());

		numbersList = new ArrayList<String>();

		numbersList = currentContact.getPhoneNumbers();
		
		Log.d("", ">> numbersList.length" + numbersList.size());

		chooseNumberListViewAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, numbersList);

		chooseNumberListView.setAdapter(chooseNumberListViewAdapter);

		chooseNumberListView.setOnItemClickListener(this);
	}

	

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// TODO Auto-generated method stub

		TextView selectedTextView = (TextView) view;

		AppPreferences.getInstance().setNewContactPhoneNumber(selectedTextView.getText().toString());
		
		finish();

	}

}
